﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RemotableObjects
{
    public class Maze
    {
        private int sizeOfMap=0;
        
    }

    public class MazeGrid
    {
        private List<MazeRow> gridObj { set; get; }

        private int columnCount = 0;

        private void Setup(int rows, int columns)
        {
            if (rows <= 0 || columns <= 0) throw new ArgumentOutOfRangeException("Row and Column size must be greater than zero");
            
            gridObj = new List<MazeRow>();
            for (int i = 0; i < rows; i++)
            {
                MazeRow row = new MazeRow();
                for (int j = 0; j < columns; j++)
                {
                    MazeCell cell = new MazeCell();
                    row.AddCell(cell);
                }
                gridObj.Add(row);
            }

            columnCount = columns;
        }
    }

    public class MazeRow
    {
        public List<MazeCell> Cells { get; set; }

        public MazeRow()
        {
            Cells = new List<MazeCell>();
        }

        public void AddCell(MazeCell cell)
        {
            Cells.Add(cell);
        }
    }

    public class MazeCell
    {
        public Boolean IsAlive { get; set; }

        public MazeCell()
        {
            
        }       
        
    }

    public class Treasure
    {
        private int treasureCount = 0;
        private List<TreasureHolder> treasureHolder = new List<TreasureHolder>();        

        public Treasure(int numOfTreasure)
        {
            treasureCount = numOfTreasure;
        }

        public void SetTreasure(MazeCell cell, int numOfAssign)
        {
            if (treasureCount >= numOfAssign)
            {
                treasureHolder.Add(new TreasureHolder(cell, numOfAssign));                
                treasureCount -= numOfAssign;
            }
            else
            {                
                treasureHolder.Add(new TreasureHolder(cell, treasureCount));
                treasureCount = 0;
            }
        }

        public int TakeTreasure(MazeCell cell)
        {
            int m_TreasureCount = 0;

            foreach (TreasureHolder item in treasureHolder)
	        {
                if (item.Cell.Equals(cell))
                {
                    m_TreasureCount = item.TreasureCount;
                    item.TreasureCount = 0;
                }                
	        }
            return m_TreasureCount;
        }
    }

    public class TreasureHolder
    {     

        public TreasureHolder(MazeCell cell, int count)
        {
            Cell = cell;
            TreasureCount = count;
        }

        public MazeCell Cell { get; set; }
        public int TreasureCount { get; set; }
    }


}
